


#include <iostream>

using namespace std;

int main() {
    
    string op,temp;
    char ip[100];

    int i,j,k,temp_integer,n;
    string alphabets="abcdefghijklmnopqrstuvwxyz",capital_alphabets="ABCDEFGHIJKLMNOPQRSTUVWXYZ",numbers="0123456789";
    
    
    cout<<"Enter the String to be encrypted\n";
    cin.getline(ip,sizeof(ip));
    
    cout<<"\nEnter the size of key\n";
    cin>>n;
    char key[n];
    
    cout<<"\nEnter the key\n";
    for(j=0;j<n;j++)
    cin>>key[j];

    temp=ip;

    for(i=0,j=0;temp[i]!='\0';i++,j++)
    {
            
            
             if(j>=n)
                 j=0;

            if((int)temp[i]<=122&&(int)temp[i]>=97)
            {
                temp_integer=((int)temp[i]-97+(int)key[j]-48)%26;
                op+=alphabets[temp_integer];
            }
           
            else if(temp[i]>=65&&temp[i]<=91)
            {
                temp_integer=((int)temp[i]-65+(int)key[j]-48)%26;
                op+=capital_alphabets[temp_integer];
            }
        
            else if(temp[i]>=48&&temp[i]<=57)
            {
                temp_integer=((int)temp[i]-48+(int)key[j]-48)%10;
                op+=numbers[temp_integer];
            }
        
            else if((int)temp[i]==32)
                op+=" ";
        
            else
                op+=(char)((int)(temp[i])+(int)key[j]-48);
    }
	


        cout<<"\nEncrypted String is "<<op<<endl;
        temp=op;
        op="";

	
    for(i=0,j=0;temp[i]!='\0';i++,j++)
    {
            
            
             if(j>=n)
                 j=0;

            if((int)temp[i]<=122&&(int)temp[i]>=97)
            {
                temp_integer=(((int)temp[i]-97)+(26-((int)key[j]-48)))%26;
                op+=alphabets[temp_integer];
            }
           
            else if((int)temp[i]>=65&&(int)temp[i]<=91)
            {
                temp_integer=(((int)temp[i]-65)+(26-((int)key[j]-48)))%26;
                op+=capital_alphabets[temp_integer];
            }
        
            else if((int)temp[i]>=48&&(int)temp[i]<=57)
            {
                temp_integer=(((int)temp[i]-48)+(10-((int)key[j]-48)))%10;
                op+=numbers[temp_integer];
            }
        
      	    else if((int)temp[i]==32)
                op+=" ";
        
            else
                op+=(char)((int)(temp[i])+(int)key[j]-48);
    }
	

        cout<<"\nDecrypted String is "<<op<<endl;
        

    return 0;
}


/*
 #include <iostream>
 #include <ctime>
 
 using namespace std;
 
 int main( )
 {
 // current date/time based on current system
 time_t now = time(0);
 
 // convert now to string form
 char* dt = ctime(&now);
 
 cout << "The local date and time is: " << dt << endl;
 
 // convert now to tm struct for UTC
 tm *gmtm = gmtime(&now);
 dt = asctime(gmtm);
 cout << "The UTC date and time is:"<< dt << endl;
 }
 */
